Skip to content

查找绑定窗口图片1 - FindWindowsFromPathAll

函数简介

在绑定窗口的指定区域内查找指定图像的所有匹配位置,模板通过文件路径指定,支持多图,返回全部匹配结果。

接口名称

FindWindowsFromPathAll

DLL调用

long FindWindowsFromPathAll(long instance, int x1, int y1, int x2, int y2, string templ, string deltaColor, double matchVal);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
x1整数型搜索区域左上角X坐标。
y1整数型搜索区域左上角Y坐标。
x2整数型搜索区域右下角X坐标。
y2整数型搜索区域右下角Y坐标。
templ字符串模板图片的路径,可用 | 分隔多图,如 "test.bmp|test2.bmp|test3.bmp"默认任一模板不存在或加载失败时整次返回空;可通过 SetConfigByKey 设置 MultiTemplateAbortOnInvalidImage=false 跳过无效模板继续匹配。
deltaColor字符串颜色差值,格式为"RRGGBB",如"101010"。
matchVal双精度浮点数相似度,如0.85,最大为1。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// 0,0,0,0 表示绑定窗口整个客户区
auto results = ola.FindWindowsFromPathAll(0, 0, 0, 0, "img/btn_ok.bmp", "101010", 0.9);
if (!results.empty() && results[0].MatchState) {
    int x = results[0].X;
    int y = results[0].Y;
}
csharp
using OLAPlug;

var ola = new OLAPlugServer();
// 0,0,0,0 表示绑定窗口整个客户区
var results = ola.FindWindowsFromPathAll(0, 0, 0, 0, "img/btn_ok.bmp", "101010", 0.9);
if (results.Count > 0 && results[0].MatchState)
{
    int x = results[0].X;
    int y = results[0].Y;
}
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
# 0,0,0,0 表示绑定窗口整个客户区
results = ola.FindWindowsFromPathAll(0, 0, 0, 0, "img/btn_ok.bmp", "101010", 0.9)
if results and results[0].get("MatchState"):
    x = results[0]["X"]
    y = results[0]["Y"]
java
import com.olaplug.OLAPlugServer;
import com.olaplug.model.MatchResult;
import java.util.List;

OLAPlugServer ola = new OLAPlugServer();
// 0,0,0,0 表示绑定窗口整个客户区
List<MatchResult> results = ola.FindWindowsFromPathAll(0, 0, 0, 0, "img/btn_ok.bmp", "101010", 0.9);
if (results != null && !results.isEmpty() && results.get(0).MatchState) {
    int x = results.get(0).X;
    int y = results.get(0).Y;
}
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
// 0,0,0,0 表示绑定窗口整个客户区
auto results = ola.FindWindowsFromPathAll(0, 0, 0, 0, "img/btn_ok.bmp", "101010", 0.9)
if (!results.empty() && results[0].MatchState) {
    x := results[0].X
    y := results[0].Y
}
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
// 0,0,0,0 表示绑定窗口整个客户区
auto results = ola.find_windows_from_path_all(0, 0, 0, 0, "img/btn_ok.bmp", "101010", 0.9)
if (!results.empty() && results[0].MatchState) {
    let x = results[0].X;
    let y = results[0].Y;
}
cpp
var ola = com("OlaPlug.OlaSoft")
// 0,0,0,0 表示绑定窗口整个客户区
var results = ola.FindWindowsFromPathAll(0, 0, 0, 0, "img/btn_ok.bmp", "101010", 0.9)
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
' 0,0,0,0 表示绑定窗口整个客户区
results = ola.FindWindowsFromPathAll(0, 0, 0, 0, "img/btn_ok.bmp", "101010", 0.9)
text
.局部变量 ola, OLAPlug
.局部变量 retData, MatchData, , 数组
.局部变量 count, 整数型
.局部变量 rawstring, 文本型
ola.创建 ()
' 易语言 SDK 与其它语言不同:不直接返回列表,而是返回找到数量,结果写入 retData
' 0,0,0,0 表示绑定窗口整个客户区
count = ola.FindWindowsFromPathAll (0, 0, 0, 0, "img/btn_ok.bmp", "101010", 0.9, retData, rawstring)
' rawstring 为原始 JSON 数组文本(可空,可省略);仅在需要 ParseMatchImageAllJson / SortPosDistance 等时再传
.如果真 (count > 0)
    ' 一般直接遍历 retData 即可(下标从 1 开始),无需再 Parse
    ' 例:retData [1].X、retData [1].Y、retData [1].MatchState
.如果真结束
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
// 0,0,0,0 表示绑定窗口整个客户区
var results = ola.FindWindowsFromPathAll(0, 0, 0, 0, "img/btn_ok.bmp", "101010", 0.9);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
// 0,0,0,0 表示绑定窗口整个客户区
MatchDataList results = ola.FindWindowsFromPathAll(0, 0, 0, 0, "img/btn_ok.bmp", "101010", 0.9)
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
// 0,0,0,0 表示绑定窗口整个客户区
auto results = ola.FindWindowsFromPathAll(0, 0, 0, 0, "img/btn_ok.bmp", "101010", 0.9);
if (!results.empty() && results[0].MatchState) {
    int32_t x = results[0].X;
}

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long ptr = FindWindowsFromPathAll(instance, 0, 0, 0, 0, "img/btn_ok.bmp", "101010", 0.9);
if (ptr != 0) {
    char json[8192] = {0};
    GetStringFromPtr(ptr, json, sizeof(json));
    int matchState = 0, x = 0, y = 0, width = 0, height = 0, index = 0;
    double matchVal = 0, angle = 0;
    ParseMatchImageAllJson(instance, json, 0, &matchState, &x, &y, &width, &height, &matchVal, &angle, &index);
    FreeStringPtr(instance, ptr);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long FindWindowsFromPathAll(long ola, int x1, int y1, int x2, int y2, string templ, string deltaColor, double matchVal);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int ParseMatchImageAllJson(string str, int parseIndex, out int matchState, out int x, out int y, out int width, out int height, out double matchVal, out double angle, out int index);

long instance = CreateCOLAPlugInterFace();
long ptr = FindWindowsFromPathAll(instance, 0, 0, 0, 0, "img/btn_ok.bmp", "101010", 0.9);
if (ptr != 0) {
    StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
    GetStringFromPtr(ptr, sb, sb.Capacity);
    FreeStringPtr(ptr);
    ParseMatchImageAllJson(sb.ToString(), 0, out int matchState, out int x, out int y, out int w, out int h, out double mv, out double ang, out int idx);
}
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ptr = ola.FindWindowsFromPathAll(instance, ...)
# 原生返回 JSON 数组指针,用 ParseMatchImageAllJson(instance, json, 0, ...) 取第一项

返回值

调用方式返回值说明
SDKMatchData/MatchResult 列表(Python 为 list[dict]全部匹配结果;空列表表示未找到
SDK(火山)MatchDataList结构化结果列表
SDK(易语言)整数型 + retDataMatchData 数组)返回找到数量,结果写入 retData;内部为 GetStringFromPtr + OL_获取MatchDataAll;可选 rawstring 拿原始 JSON
原生 DLL非 0成功,返回 JSON 数组字符串指针,需调用 FreeStringPtr 释放
原生 DLL0失败

返回数据格式:

json
[{
    "MatchVal": 0.85,
    "MatchState": true,
    "Index": 0,
    "X": 100,
    "Y": 200,
    "Width": 100,
    "Height": 100
}]
字段名类型说明
MatchVal浮点数匹配相似度。
MatchState布尔是否匹配成功。
Index整数结果索引(从 0 开始)。
X整数X 坐标。
Y整数Y 坐标。
Width整数宽度。
Height整数高度。

相关配置

配置项类型默认说明
MultiTemplateAbortOnInvalidImagebooltrue多模板路径 | 分隔时,某一图不存在或加载失败:true默认)整次返回空;false 跳过无效模板继续匹配(全局配置,见 SetConfigByKey)。

注意事项

项目说明
搜索范围x1、y1、x2、y2都传0时,将搜索整个窗口客户区。